package com.jshx.sz.gdjt.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.jshx.sz.gdjt.R;
import com.jshx.sz.gdjt.constant.ApplicationGlobal;
import com.jshx.sz.gdjt.control.HeaderView;
import com.jshx.sz.gdjt.thread.ToolThread;
import com.jshx.sz.gdjt.util.ProgressDialogUtil;
import com.jshx.sz.gdjt.util.ToastUtil;
import com.xmz.activity.MovieAdapter;
import com.xmz.activity.MovieLayout;

/**
 * 工具列表界面
 * @author caxiang
 * @time 2013-08-21
 */
public class ToolsListActivity extends SuperActivity 
{
	
	/**
	 * 标题栏组件
	 */
	private HeaderView header;
	
	/**
	 * 列表组件
	 */
	private ListView toolsList;
	
	/**
	 * 组件实例化工具
	 */
	private LayoutInflater layoutInflater;
	private LinearLayout lltop;
	
	/**
	 * 工具数据容器
	 */
	private ArrayList<HashMap<String, String>> data=new ArrayList<HashMap<String,String>>();
	
 
	private String[] types={"主板","CPU","内存","硬盘","显卡","显示器","机箱","电源","光驱","散热器","声卡","扩展卡"};
	private void  initList()
	{
		adapter=new MovieAdapter(this);
		for(int i=0;i<types.length;i++)
		{
			HashMap<String,String> map=new HashMap<String, String>();
			map.put("IMAGE", "主板");
			map.put("TYPE", types[i]);
			data.add(map);
			
			Map<String,Object> map1=new HashMap<String,Object>();
	        map1.put("image", getResources().getDrawable(R.drawable.image));
	        map1.put("text",  types[i]);
	        adapter.addObject(map1);
		}
	}
	
	
	 private MovieLayout movieLayout;
	 private MovieAdapter adapter;
	    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.toolslist_activity);
		TAG = "ToolsListActivity";
		layoutInflater = LayoutInflater.from(this);
		initList();
		findView();
		initView();
		
		
		movieLayout=(MovieLayout)findViewById(R.id.movieLayout);
        movieLayout.setAdapter(adapter);
        
	}

	/**
	 * 实例化页面组件
	 */
	private void findView() {
		header = (HeaderView)findViewById(R.id.toolslist_header);
		toolsList = (ListView)findViewById(R.id.toolslist);
//		lltop= (LinearLayout)findViewById(R.id.lltop);
	}

	/**
	 * 初始化页面数据和页面组件
	 */
	private void initView() {
		header.setTitle("主页面");
	 
		String type ="";//类型
		String userId = ApplicationGlobal.userId;//用户编号
//		String orderNos =  getIntent().getStringExtra("orderNos");;//工单列表
		String orderNos = "364201%2C364249%2C365528";//工单列表
		//String orderNos = "364201";//工单列表
		
	 
		toolsList.setAdapter(myAdapter);
		 
		
//		lltop.setOnTouchListener(new OnTouchListener() {
//			
//			@Override
//			public boolean onTouch(View v, MotionEvent event) {
//				Log.e("onTouch", "MotionEvent.ACTION_MOVE"); 
//
//				return MotionEvent.ACTION_MOVE == event.getAction() ? true : false; 
//			}
//		});
		
	}
	
	 
	/**
	 * listVIew数据适配器
	 */
	private BaseAdapter myAdapter = new BaseAdapter()
	{
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			convertView = layoutInflater.inflate(R.layout.tools_list_item, null);
			TextView type_name = (TextView)convertView.findViewById(R.id.type_name);
			HashMap map=(HashMap)data.get(position);
			type_name.setText(map.get("TYPE")+"");
			
			convertView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					TextView tn=(TextView)v.findViewById(R.id.type_name) ;
					// TODO Auto-generated method stub
					Toast.makeText(ToolsListActivity.this, tn.getText()+"", Toast.LENGTH_SHORT).show();
				}
			});
			return convertView;
		}
		
		@Override
		public long getItemId(int position) {
			return position;
		}
		
		@Override
		public Object getItem(int position) {
			return data.get(position);
		}
		
		@Override
		public int getCount() {
			return data.size();
		}
		
	};
	
	
	
}
